package com.weixin.paleituo.fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.base.BaseFragment;
import com.weixin.paleituo.bean.PurchaseBean;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.util.StringUtils;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.ItemBuyHouseStepView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author yichao
 * Time  2017/12/19 14:40
 * Dest  预定房子
 */

public class PredetermineHouseFragment extends BaseFragment {
    @BindView(R.id.itembuyhousestepview_ordernumber_activity_buyhousestep)
    ItemBuyHouseStepView mItembuyhousestepviewOrdernumberActivityBuyhousestep;
    @BindView(R.id.itembuyhousestepview_time_activity_buyhousestep)
    ItemBuyHouseStepView mItembuyhousestepviewTimeActivityBuyhousestep;
    @BindView(R.id.itembuyhousestepview_salenumber_activity_buyhousestep)
    ItemBuyHouseStepView mItembuyhousestepviewSalenumberActivityBuyhousestep;
    @BindView(R.id.itembuyhousestepview_payformoney_activity_buyhousestep)
    ItemBuyHouseStepView mItembuyhousestepviewPayformoneyActivityBuyhousestep;
    @BindView(R.id.itembuyhousestepview_payfor_style_activity_buyhousestep)
    ItemBuyHouseStepView mItembuyhousestepviewPayforStyleActivityBuyhousestep;
    @BindView(R.id.tv_consultant_content_fragment_predetermine_house)
    TextView mTvConsultantContentFragmentPredetermineHouse;
    @BindView(R.id.tv_contact_fragment_predeternine_house)
    TextView mTvContactFragmentPredeternineHouse;
    @BindView(R.id.ll_counselor_fragment_predeternine_house)
    LinearLayout mLlCounselorFragmentPredeternineHouse;
    private String mPhone;


    @Override
    public View initView(Context context) {
        View visitHouseView = UIUtils.inflate(context, R.layout.fragment_predetermine_house);
        return visitHouseView;
    }

    @Override
    protected void initData() {
        super.initData();

        Bundle arguments = getArguments();
        PurchaseBean purchaseBean = arguments.getParcelable(Contans.INTENT_DATA);

        if (purchaseBean != null) {
            mItembuyhousestepviewOrdernumberActivityBuyhousestep.setTvContent(purchaseBean.getOrderId() + "");
            mItembuyhousestepviewTimeActivityBuyhousestep.setTvContent(purchaseBean.getAdvancetime() + "");
            mItembuyhousestepviewPayformoneyActivityBuyhousestep.setTvContent(purchaseBean.getAdvancemoney() + "");
            mItembuyhousestepviewPayforStyleActivityBuyhousestep.setTvContent(payforMent(purchaseBean.getPayment() + ""));
            if (purchaseBean.getpSeller() == 1 && !StringUtils.isEmpty(purchaseBean.getName()) && !StringUtils.isEmpty(purchaseBean.getPhone()) && !StringUtils.isEmpty(purchaseBean.getJobNumber())) {
                mPhone = purchaseBean.getPhone();
                mLlCounselorFragmentPredeternineHouse.setVisibility(View.VISIBLE);
                mTvConsultantContentFragmentPredetermineHouse.setText(purchaseBean.getName());
                mItembuyhousestepviewSalenumberActivityBuyhousestep.setTvContent(purchaseBean.getJobNumber());

            } else {
                mLlCounselorFragmentPredeternineHouse.setVisibility(View.GONE);
            }
        }
    }

    public String payforMent(String value) {
        String ss = "";
        if (value.equals("1")) {
            ss = "支付宝";
        } else if (value.equals("2")) {
            ss = "微信";
        } else if (value.equals("3")) {
            ss = "线下";
        }
        return ss;
    }

    public static BaseFragment newInstance(PurchaseBean purchase) {
        PredetermineHouseFragment predetermineHouseFragment = new PredetermineHouseFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable(Contans.INTENT_DATA, purchase);
        predetermineHouseFragment.setArguments(bundle);
        return predetermineHouseFragment;
    }
    @OnClick(R.id.tv_contact_fragment_predeternine_house)
    public void onViewClicked() {
        try {
            Intent dialIntent =  new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mPhone));
            mContext.startActivity(dialIntent);
        }catch (Exception e){

        }



    }
}
